< previous page page_237 next page >

Page 237
For example, the files Mand1_0.bmp, Mand1_1.bmp, and so forth on the CD-ROM form an animation that zooms in on part of the Mandelbrot set. Some of those images took several minutes to generate. A typical personal computer cannot generate those images quickly enough to display them in an animation program.
If your program can generate images quickly enough, you can take a couple of different approaches to displaying them. The clear-and-redraw method is simple and uses only Visual Basic graphic methods. It is fairly slow, however, and limited to a few dozen frames per second for a simple animation.
The save-and-restore method achieves better speed by updating only the parts of the image that change between frames. This technique also uses only Visual Basic graphic methods.
By using the GetBitmapBits and SetBitmapBits API functions, you can improve the speed of these methods to make them useful in a wider variety of circumstances.
Clear and Redraw
In the simplest form of drawing animation, you clear the entire picture and redraw it for each frame. Example program Stocks1, shown in Figure 8.2, uses this method to animate a random stock portfolio.
The following code shows how program Stocks1 works. The stock price data is stored in the array Data where Data(F, S) is the price for stock number S in frame number F.
Before starting the animation, the program draws the animation's background on the picGraph picture box. It then sets the control's Picture property equal to its Image property. That makes the image a permanent part of the control's background. Before it draws each frame, the program uses the Cls method to clear the picture box and restore this background quickly and easily. It then draws rectangles to represent the stock values.
0237-01.jpg
Figure 8.2
Program Stocks1 animates a random stock portfolio.

 
< previous page page_237 next page >